<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./node_modules/nprogress/nprogress.js"></script>
    <link rel="stylesheet" href="./node_modules/nprogress/nprogress.css">
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>

</head>

<body>
    <button>点击</button>
    <script>
        const request = axios.create({
            baseURL: 'http://localhost:8080',
            timeout: 20000
        })

        request.interceptors.request.use(config => {
            // 开启loading效果
            NProgress.start();
            return config;
        }, error => {
            // Do something with request error
            return Promise.reject(error);
        });

        request.interceptors.response.use(response => {
            // 关闭loading
            NProgress.done();
            return response.data;// 简化服务器数据
        })



        

        let oBtn = document.querySelector('button');
        oBtn.onclick = function () {
            request.get('/timeout').then(data => {
                console.log('data: ', data);
            })
        }


    </script>
</body>

</html>